

#include "Jmic.h"
#include "DigitalIn.h"
namespace duer
{

#if 0
mbed::DigitalIn GPIO22(GPIO_PIN22);
mbed::DigitalIn GPIO23(GPIO_PIN23);

void YtJmic::rx_irq_handler()
{
    while(_serical->readable()) {
    	if(rxReadSize < sizeof(rxBuf)){
        	rxBuf[rxReadSize] = _serical->getc();		
			rxReadSize++;	
    	}
    }
}

void YtJmic::init()
{
    mbed::Callback<void ()> callback(this, &YtJmic::rx_irq_handler);

	_serical = new mbed::Serial(UART0_TX,UART0_RX);	
	//_serical->baud(921600);
	_serical->baud(9600);
    //_serical->format(8, mbed::SerialBase::None, 1);
    _serical->attach(callback, mbed::SerialBase::RxIrq);

	memset(rxBuf, 0x00 ,sizeof(rxBuf));
	rxReadSize = 0;
}

void YtJmic::deinit()
{
	_serical->baud(921600);	
    //_serical->attach(NULL, mbed::SerialBase::RxIrq);
}

int YtJmic::get_rxReadSize()
{
	return rxReadSize;
}

bool YtJmic::is_ready()
{
	return (rxReadSize >= 15)?true:false;
}

void YtJmic::puts(char *pDataToSend, int nByteNumberToSend)
{
	int i = 0;
	for(i = 0; i < nByteNumberToSend; i++)
		_serical->putc(pDataToSend[i]);
}

void YtJmic::gets(char *pDataReceived, int pReceivedByteNumber)
{
	memcpy(pDataReceived,rxBuf,pReceivedByteNumber);
}
#endif
}
